When implementing an OPC server with the OPC Wizard consists, your code needs to perform the following basic steps:
The properties and the contents of the server object must be defined before the server is started.
The OPC server is started by calling the Start Method. The server must not already be started at that moment. This method initializes the server operations, sets up its address space, and initiates listening on the configured endpoints for client connections.
The Start Method operates asynchronously. The server may not yet be ready to accept client connections on all its endpoints when this method completes.
After you call the Start Method, let the server run for as long as needed.
The OPC server is stopped by calling the Stop Method. The server must be running (started) at that moment. This method stops the server operations, initiates disconnecting any existing client connections and ceasing to listen on the configured endpoints. This method performs a graceful shutdown of the server, ensuring that resources are properly released and that clients are notified of the disconnection.
The Stop Method operates asynchronously. The server may not yet have disconnected all client connections on all its endpoints when this method completes.
The following example illustrates how to start and stop the OPC server.
The server object raises the Starting Event when the component is starting, and it raises the Stopped Event when the component has stopped.
These notifications are also broadcast to all server nodes, and can be handled on any server node too.
Example: Examples - Server OPC UA - React to server starting and stopping in push model
The server object implements the IEasyUAServerEndpointMonitoring Interface, and provides notification about the state of its endpoints via the EndpointStateChanged Event. For more information, see OPC Wizard Operation Monitoring Services.
The following example illustrates how to receive notifications about endpoint state changes.